home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / linalg / apply_givens.c next >
Encoding:
C/C++ Source or Header  |  2001-06-19  |  1.9 KB  |  58 lines

  1. /* linalg/apply_givens.c
  2.  * 
  3.  * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 Gerard Jungman, Brian Gough
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or (at
  8.  * your option) any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. inline static void
  21. apply_givens_qr (size_t M, size_t N, gsl_matrix * Q, gsl_matrix * R,
  22.          size_t i, size_t j, double c, double s)
  23. {
  24.   size_t k;
  25.  
  26.   /* Apply rotation to matrix Q,  Q' = Q G */
  27.  
  28.   for (k = 0; k < M; k++)
  29.     {
  30.       double qki = gsl_matrix_get (Q, k, i);
  31.       double qkj = gsl_matrix_get (Q, k, j);
  32.       gsl_matrix_set (Q, k, i, qki * c - qkj * s);
  33.       gsl_matrix_set (Q, k, j, qki * s + qkj * c);
  34.     }
  35.  
  36.   /* Apply rotation to matrix R, R' = G^T R (note: upper triangular so
  37.      zero for column < row) */
  38.  
  39.   for (k = GSL_MIN (i, j); k < N; k++)
  40.     {
  41.       double rik = gsl_matrix_get (R, i, k);
  42.       double rjk = gsl_matrix_get (R, j, k);
  43.       gsl_matrix_set (R, i, k, c * rik - s * rjk);
  44.       gsl_matrix_set (R, j, k, s * rik + c * rjk);
  45.     }
  46. }
  47.  
  48. inline static void
  49. apply_givens_vec (gsl_vector * v, size_t i, size_t j, double c, double s)
  50. {
  51.   /* Apply rotation to vector v' = G^T v */
  52.  
  53.   double vi = gsl_vector_get (v, i);
  54.   double vj = gsl_vector_get (v, j);
  55.   gsl_vector_set (v, i, c * vi - s * vj);
  56.   gsl_vector_set (v, j, s * vi + c * vj);
  57. }
  58.